package LeetCode热题HOT100;

import 剑指offer.ListNode;

public class p21合并两个有序链表 {
    public ListNode mergeTwoLists(ListNode list1, ListNode list2) {
        ListNode head=new ListNode();
        ListNode curNode=head;

        ListNode cur1=list1;
        ListNode cur2=list2;

        while (cur1!=null && cur2!=null) {
            if (cur1.val<cur2.val) {
                curNode.next=cur1;
                cur1=cur1.next;
            }else {
                curNode.next=cur2;
                cur2=cur2.next;
            }
            curNode=curNode.next;
        }

        if (cur1==null) {
            curNode.next=cur2;
        }

        if (cur2==null) {
            curNode.next=cur1;
        }

        //curNode.next=cur1==null?cur2:cur1;

        return head.next;

    }
}
